#!/bin/bash

echo -e "\n================================================================
Cream Framework v1.2 - Plugin creation
----------------------------------------------------------------
Author            : Maelstrom <devcreamframework@gmail.com>
Public repository : http://code.google.com/p/cream-cms-repository/
================================================================\n"

nativePath='../core/classes/natives'
controllersPath='../core/controllers/natives'
nativesControllerFile='../core/controllers/natives.ctrl.php'
pageTop="<?php

/**
 * Cream Framework
 * 
 * NOTICE OF LICENSE
 * See licence file @ ./LICENSE/license.txt
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade the Cream Framework to newer
 * versions in the future. If you wish to customize the Cream Framework for your
 * needs please refer to https://github.com/maelstromkd/cream-dev.git for more information.
 *
 * @author      Maelstrom <devcreamframework@gmail.com>
 * @link        https://github.com/maelstromkd/cream-dev.git
 * @version     1.2
 */

if (! defined ( '__ROOT__' )) exit ( 'Direct access not allowed' );"


# CREATE CLASS ------------------------------------------------------
while [ -z $className ]
do
    read -p "Class name : " className
done

# LOWERCASE CLASSNAME
classNameLowerCase=$className
declare -l string classNameLowerCase
classNameLowerCase=$classNameLowerCase

# CAPITALIZE CLASSNAME
classNameCap=$className
declare -c string classNameCap
classNameCap=$classNameCap

echo -e "$pageTop

# Begin file

class $classNameCap{

	public function __construct(){
		// code
	}

}

# End of file">$nativePath'/'$classNameLowerCase".class.php"
# -------------------------------------------------------------------



# CREATE CONTROLLER -------------------------------------------------
while [ -z $response ] && [[ $response != 'o' && $response != 'n' ]]
do
    read -p "Need controller ? (o/n) : " response
done

if [ $response == "o" ]
then

	mkdir $controllersPath"/$classNameLowerCase"
	mkdir $controllersPath"/$classNameLowerCase/frontend"
	mkdir $controllersPath"/$classNameLowerCase/backend"
	frontendControllerPath=$controllersPath"/$classNameLowerCase/frontend"
	backendControllerPath=$controllersPath"/$classNameLowerCase/backend"
	frontendController=$controllersPath"/$classNameLowerCase/frontend/$classNameLowerCase.ctrl.php"
	backendController=$controllersPath"/$classNameLowerCase/backend/$classNameLowerCase.ctrl.php"

	echo -e "$pageTop"'

# Begin file

switch($_APP->page){
	
}

# End of file'>$frontendController
	echo -e "$pageTop"'

# Begin file

switch($_APP->page){
	
}

# End of file'>$backendController
echo -e "include __CTRL__ . 'natives' . DS . '$classNameLowerCase' . DS . "'$context'" . DS . '$classNameLowerCase.ctrl.php';">>$nativesControllerFile
fi
# -------------------------------------------------------------------

echo -e "\nComplete !\n"